<!--
 * @Author: Zhouxin 2201_75539691@noreply.gitcode.com
 * @Date: 2024-11-20 20:42:31
 * @LastEditors: Zhouxin 2201_75539691@noreply.gitcode.com
 * @LastEditTime: 2024-11-20 20:47:05
 * @FilePath: \2024.11.20-day08-数组与字符串\demo4.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 要求将数组中的0项去掉，将不为0的值存入一个新的数组，生成新的数组 -->

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arr1 = [0, 6, 3, 0, 4, 0, 1, 8, 0, 10];
        var arr2 = [];
        for (var i = 0; i < arr1.length; i++) {
            if (arr1[i] !== 0) {
                arr2.push(arr1[i]);
            }
        }
        console.log(arr2);
    </script>
</body>

</html>